package com.qysoft.modules.genTable.action;


import com.jfinal.aop.Before;
import com.qysoft.modules.genTable.entity.GenScheme;
import com.qysoft.modules.genTable.service.GenSchemeService;
import com.qysoft.rapid.actions.JsonResultInterceptor;
import com.qysoft.rapid.actions.RapidAction;
import com.qysoft.rapid.core.RapidDbConnTx;
import com.qysoft.rapid.dao.mybatis.RapidDao;
import com.qysoft.rapid.dao.mybatis.common.CommonDao;

import java.util.List;

public class GenSchemeAction extends RapidAction {

	public void index() throws Exception{

		bindCurrentRyxxToPage();
		List<Object> tableList = CommonDao.selectListByXml("Dynasearch_genTable_getData");
		setAttr("tableList",tableList);
		renderJsp("genScheme.jsp");
	}

	/**
	 * 保存方案
	 * @throws Exception
	 */
	@Before({RapidDbConnTx.class,JsonResultInterceptor.class})
	public void saveSCHEME()throws Exception{

		GenScheme scheme = getBean(GenScheme.class,"");
		scheme.setSub_module_name("");
		scheme.setUpdateBy(getCurrentRyxx().getId());
		if(scheme.getId() == null){
			scheme.setCreateBy(getCurrentRyxx().getId());
			RapidDao.insertByXml("genScheme_insert",scheme);
		}else {
			RapidDao.insertByXml("genScheme_update",scheme);
		}
		GenSchemeService.createCode(scheme);
	}

	/**
	 * 查询单个
	 * @throws Exception
	 */
	@Before(JsonResultInterceptor.class)
	public void query_genScheme_one() throws Exception{

		String id = getPara("id");
		GenScheme genScheme = CommonDao.selectOneByXml("query_genScheme_one",id);
		setJson(genScheme);
	}

	/**
	 * 删除方案
	 * @throws Exception
	 */
	@Before(JsonResultInterceptor.class)
	public void delete()throws Exception{

		String id = getPara("id");
		RapidDao.deleteByXml("genScheme_delete",id);
	}
}
